package Exam.ArrayListDemo;

import java.util.ArrayList;

public class ArrayListDemo4 {
    public static void main(String[] args) {
        //定义一个集合，添加一些学生对象，并进行遍历学生类的属性为：姓名，年龄
        ArrayList<Student> list = new ArrayList<>();

        Student s1 = new Student("shasha",22);
        Student s2 = new Student("jiejie",22);
        Student s3 = new Student("geigei",8);

        //添加元素
        list.add(s1);
        list.add(s2);
        list.add(s3);

        //遍历集合
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName()+","+stu.getAge());
        }

    }
}
